<template>
  <!--  外部div-->
  <div class="login">
    <div class="title">
      <el-image
          style="width: 100px; height: 100px"
          :src="require('./assets/images/logo.png')"
          fit="contain"></el-image>
      <div class="text">
        <div class="subTitle">高新区（天元区）项目服务管理平台</div>
        <div class="engtext">TIANYUAN DISTRICT PROJECT SERVICE MANAGEMENT PLATFORM</div>
      </div>

    </div>
    <div style="height: 5vh"></div>
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
        <h3 class="title">登录平台</h3>
        <el-form-item prop="username">
          <el-input
              v-model="loginForm.username"
              type="text"
              auto-complete="off"
              placeholder="账号"
          >
            <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
              v-model="loginForm.password"
              type="password"
              auto-complete="off"
              placeholder="密码"
              @keyup.enter.native="handleLogin"
          >
            <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
          </el-input>
        </el-form-item>
        <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 15px 50%;">记住密码</el-checkbox>
        <el-form-item style="width:100%;">
          <el-button
              :loading="loading"
              size="medium"
              type="primary"
              style="width:100%;"
              @click.native.prevent="handleLogin"
          >
            <span v-if="!loading">登 录</span>
            <span v-else>登 录 中...</span>
          </el-button>
          <div style="float: right;" v-if="register">
            <router-link class="link-type" :to="'/register'">立即注册</router-link>
          </div>
        </el-form-item>
      </el-form>
    <div style="height: 10vh"></div>
    <!--  底部  -->
    <div class="el-login-footer">
      <span  style="font-size: 10pt">------项目服务局------</span>
    </div>
  </div>
</template>

<script>

import Cookies from "js-cookie";
import {encrypt} from "@/utils/jsencrypt";

export default {
  name: "loginView",
  data() {
    return {
      codeUrl: "",
      loginForm: {
        username: "",
        password: "",
        rememberMe: false,
        code: "",
        uuid: ""
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入您的账号" }
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码" }
        ],
        code: [{ required: true, trigger: "change", message: "请输入验证码" }]
      },
      loading: false,
      // 验证码开关
      captchaOnOff: true,
      // 注册开关
      register: false,
      redirect: undefined
    }
  },
  methods:{
    getCode(){

    },
    handleLogin() {
      console.log(Cookies.get("Admin-Token"))
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          debugger
          this.loading = true;
          if (this.loginForm.rememberMe) {
            Cookies.set("username", this.loginForm.username, { expires: 30 });
            Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
            Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
          } else {
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove('rememberMe');
          }

          this.$store.dispatch("Login", this.loginForm).then(() => {
            this.$router.push({ path: this.redirect || "/MenuIndex" }).catch(()=>{})
          }).catch(() => {
            this.loading = false;
            if (this.captchaOnOff) {
              this.getCode();
            }
          });
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  border-radius: 5px;
  height: 100%;
  background-image: url("./assets/images/logoImg.png");
  background-size: 100% 100%;

}
.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  .text{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: start;
    .subTitle{
      color: white;
      font-size: 50px;
    }
    .engtext{
      color: white;
      font-size: 15px;
      letter-spacing: 6px;
    }
  }

}

.login-form {
  border-radius: 0px 6px 6px 0;
  background: #ffffff;
  width: 300px;
  height: 275px;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-button--primary{
    //background-color: #99cc33;
  border-radius: 10px;
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.login-code-img {
  height: 38px;
}
.leftLogo{
  background-image: linear-gradient(#99cc33, #ffffff);
  width: 200px;
  height: 305px;
  //height: clientHeight / 1 ;
  //height: 1.565rem;
  //height: 32.5%;
  border-radius: 6px 0 0 6px;
  display: flex;
}
* {
  -webkit-user-select:none;
  -moz-user-select:none;
  -ms-user-select: none;
  user-select: none
}
</style>
